package cn.com.nxt.txb;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.HashMap;
import java.util.Map;

import cn.com.nxt.txb.httpdelegate.MeetingDelegate;
import cn.com.nxt.txb.util.AppUtil;
import cn.com.nxt.txb.util.AuthPreferences;
import cn.com.nxt.txb.widget.ClearEditText;

@ContentView(R.layout.activity_meeting_password)
public class MeetingPasswordActivity extends BaseActivity {
    @ViewInject(R.id.toolbar)
    private Toolbar toolbar;
    @ViewInject(R.id.et_password)
    private ClearEditText mPwdEt;
    @ViewInject(R.id.tv_save)
    private TextView mSaveTv;
    @ViewInject(R.id.tv_title)
    private TextView mTitleTv;
    private boolean isComperePassword;
    private MeetingDelegate delegate;
    private String password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);//注解绑定
        delegate=new MeetingDelegate(this);
        isComperePassword = getIntent().getBooleanExtra("compere_password", false);
        if (isComperePassword) {
            mTitleTv.setText("主持人密码");
            mPwdEt.setHint("主持人密码");
        }else{
            password=getIntent().getStringExtra("initiation_password");
            mPwdEt.setText(password);
        }
    }

    @Event({R.id.tv_save})
    private void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.tv_save:
                save();
                break;
        }
    }

    private void save() {
        password = mPwdEt.getText().toString().trim();
        Map<String, String> map = new HashMap<>();
        map.put("mute_model", MeetingSetActivity.model+"");
        map.put("password", password);
        Gson gson = new Gson();
        showDialog("正在设置");
        Log.v("--setting--", gson.toJson(map));
        delegate.setMeetingSettingInfo(AppUtil.mUser.getToken(),gson.toJson(map),MeetingSetActivity.RESULT_SILENT_MODE);
    }

    @Override
    public void success(String result, byte flag) {
        super.success(result, flag);
        disDialog();
        MeetingSetActivity.password=password;
        Intent intent = new Intent();
        setResult(MeetingSetActivity.RESULT_INITIATION_PASSWORD, intent);
        finish();
    }
}
